home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / demos / demobook / MainWindow.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  61.5 KB  |  2,027 lines

  1. /*
  2.  * Copyright (C) 1993, 1994, Silicon Graphics, Inc.
  3.  * All Rights Reserved.
  4.  *
  5.  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6.  * the contents of this file may not be disclosed to third parties, copied or
  7.  * duplicated in any form, in whole or in part, without the prior written
  8.  * permission of Silicon Graphics, Inc.
  9.  *
  10.  * RESTRICTED RIGHTS LEGEND:
  11.  * Use, duplication or disclosure by the Government is subject to restrictions
  12.  * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13.  * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14.  * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15.  * rights reserved under the Copyright Laws of the United States.
  16.  */
  17. #include <stdio.h>            /* standard libraries */
  18. #include <stdlib.h>
  19. #include <unistd.h>
  20. #include <math.h>
  21. #include <sys/time.h>
  22. #include <Xm/Xm.h>                      /* motif lib */
  23. #include <X11/Xirisw/GlxMDraw.h>        /* GL/X widget lib */
  24. #include <X11/StringDefs.h>             /* X11 libs */
  25. #include <X11/keysym.h>
  26. #include <Xm/Separator.h>               /* motif widget libs */
  27. #include <Xm/Form.h>
  28. #include <Xm/CascadeB.h>
  29. #include <Xm/PushB.h>
  30. #include <Xm/ToggleB.h>
  31. #include <Xm/RowColumn.h>
  32. #include <Xm/Frame.h>
  33. #include "interfmotif.h"                /* private header files */
  34. #include "exinterfmotif.h"
  35. #include "bookglo.h"
  36. /*
  37. #include "exbookglo.h"
  38. #include "shelves.h"
  39. */
  40. #include "globals.h"
  41. #include "exglobals.h"
  42. #include "interf.h"
  43.  
  44. #define MOTION 1
  45. #define NO_MOTION 0
  46. #define PRESSED TRUE
  47. #define RELEASED FALSE
  48. #define DOUBLETIME .6
  49.  
  50. /* functions */
  51. extern struct indexlist *find_keyword();
  52. extern void setup_colors_widget();
  53.  
  54. /* global variables */
  55. static int side;        /* side of page: left side is "back", right "front" */
  56. static int gSide;       /* used by Delete Demo callback */
  57. static int old_x, old_y, oldxpagendx, oldypagendx; /* used for dragging */
  58.  
  59. /* global structs */
  60. struct iconstruct *tmpiconlist; /* temp. buffer to track who's on current page */
  61. struct pagestruct *thispage;    /* tracks which page we're looking at */
  62. static Boolean MW_Button1_mode; /* tracks whether buttons are down or up */
  63. static Boolean MW_Button2_mode;
  64. static Boolean MW_dragging;     /* tracks if an icon is being dragged */
  65. static Boolean Change;          /* determines if "really quit" window come up */
  66. static long winsize_x, winsize_y; /* tracks size of window */
  67. Boolean in_main_window;         /* tracks cursor focus */
  68. static int prevmotion;          /* used for icon highlighting */
  69. Boolean AltKeyPressed = FALSE;  /* tracks alt key status */
  70.  
  71. /*global widgets */
  72. Widget MainGL;                  /* the main GL/X window. Parent is a frame */
  73. Widget CBbutton, ZLbutton, ZRbutton, ZObutton;  /* close book, zoom left/right/out */
  74. Widget OpenButton, AppendButton;/* Open, Append, book */
  75. Boolean use_pups = FALSE;       /* determines if menus use popups or not */
  76.  
  77. static GLXconfig glxconfig_Main[] = {   /* by default, GLX window is double */
  78.     {GLX_NORMAL, GLX_DOUBLE, TRUE}, /* buffered, RGB, no zbuffer size, */
  79.     {GLX_NORMAL, GLX_ZSIZE, GLX_NOCONFIG}, /* and two buffers */
  80.     {GLX_NORMAL, GLX_RGB, TRUE},
  81.     {GLX_OVERLAY, GLX_BUFSIZE, 2},
  82.     {0, 0, 0} };
  83.  
  84. static char defaultTranslations[] =      /* map X events to glx */
  85.     "<Motion>:    glxInput() \n\
  86.      <EnterNotify>:    glxInput() \n\
  87.       <LeaveNotify>:    glxInput()";
  88.  
  89. /* some dummy routine for compile without uimx stuff */
  90.  
  91. void setChange(Boolean val)
  92. {
  93.    Change = val;
  94. }
  95.  
  96. redrawevent(long val)
  97. {
  98. #ifdef DEBUG
  99. printf(" dummy redraw event routine \n");
  100. #endif
  101. }
  102. /* end of dummy routines  */
  103.  
  104. /************************************************************
  105. *
  106. * Calculate the colors to approximate the colors in the icons.
  107. *
  108. ************************************************************/
  109. initcolors()
  110. {
  111.    int i, j;
  112.    int cndx ;
  113.    float m, incr;
  114.  
  115.    cndx = 26;
  116.    for (i = 0; i < 16; i++)
  117.       {
  118.       for (j = i+1; j < 16; j++)
  119.          {
  120.          morecolors[cndx][0] = (morecolors[i+10][0] + morecolors[j+10][0]) / 2;
  121.          morecolors[cndx][1] = (morecolors[i+10][1] + morecolors[j+10][1]) / 2;
  122.          morecolors[cndx][2] = (morecolors[i+10][2] + morecolors[j+10][2]) / 2;
  123.          ++cndx;
  124.          }
  125.       }
  126.    incr = 1.0 / 16.0;
  127.    m = 0;
  128.    for (i = cndx; i < cndx+16; i++)
  129.       {
  130.       morecolors[i][0] = morecolors[2][0] * (1.0 - m) + morecolors[3][0] * m;
  131.       morecolors[i][1] = morecolors[2][1] * (1.0 - m) + morecolors[3][1] * m;
  132.       morecolors[i][2] = morecolors[2][2] * (1.0 - m) + morecolors[3][2] * m;
  133.       m = m + incr;
  134.       }
  135. }
  136.  
  137. void installcmap(Widget toplevel, Widget gl)
  138. {
  139.    Window window_list[3];
  140.    Window overlay, popup;
  141.    Arg args[5];
  142.    int n = 0;
  143.  
  144.    XtSetArg(args[n], GlxNoverlayWindow, &overlay); n++;
  145.    XtSetArg(args[n], GlxNpopupWindow, &popup); n++;
  146.    XtGetValues(gl, args, n);
  147.  
  148.    n = 0;
  149.    if (overlay)
  150.       {
  151.       window_list[n] = overlay;
  152.       n++;
  153.       }
  154.    if (popup)
  155.       {
  156.       window_list[n] = popup;
  157.       n++;
  158.       }
  159.    window_list[n] = XtWindow(toplevel); n++;
  160.    XSetWMColormapWindows(XtDisplay(toplevel), XtWindow(toplevel),
  161.     window_list, n);
  162. }
  163.  
  164. /* overlay stuff */
  165. Window overlayWindow(Widget w)
  166. {
  167.     Arg args[1];
  168.     Window overlayWindow;
  169.  
  170.     XtSetArg(args[0], use_pups?GlxNpopupWindow:GlxNoverlayWindow,
  171.              &overlayWindow);
  172.     XtGetValues(w, args, 1);
  173.     return (overlayWindow);
  174. }
  175.  
  176.    Matrix ID = { 1.0, 0.0, 0.0, 0.0,
  177.     0.0, 1.0, 0.0, 0.0,
  178.     0.0, 0.0, 1.0, 0.0,
  179.     0.0, 0.0, 0.0, 1.0};
  180. void setview()
  181. {
  182.    long winsize_x, winsize_y;
  183.  
  184.    getsize(&winsize_x, &winsize_y);
  185. /*
  186.    viewport(0.0, (float)winsize_x, 0.0, (float)(winsize_y));
  187. */
  188.    mmode(MPROJECTION);
  189.    loadmatrix(ID);
  190.    perspective(150.0, (float)winsize_x / (float)(winsize_y), 1, 505);
  191.    if (closeup == 0)
  192.       {
  193.       lookat(0.0, 6.5, 55.5, 0.0, 6.5, 0.0, 0.0);
  194.       }
  195.    else if (closeup < 0)  /* zoom to left side */
  196.       {
  197.       lookat(-5.0, 5.5, 37.5, -5.0, 5.5, 0.0, 0.0);
  198.       }
  199.    else if (closeup > 0)  /* zoom to right side */
  200.       {
  201.       lookat(5.0, 5.5, 37.5, 5.0, 5.5, 0.0, 0.0);
  202.       }
  203.    mmode(MVIEWING);
  204.    loadmatrix(ID);
  205. }
  206.  
  207. void dooverlayview()
  208. {
  209.    GLXwinset (XtDisplay(MainGL), overlayWindow(MainGL));
  210.    setview();
  211. }
  212.  
  213. /************************************************************
  214. *
  215. * Set up the viewing matrix for the book.
  216. *
  217. ************************************************************/
  218. dobookview()
  219. {
  220.    GLXwinset (XtDisplay(MainGL), XtWindow(MainGL) );
  221.    setview();
  222. }
  223.  
  224. #include <audio.h>
  225.  
  226. void silentALerror(long errnum, const char* fmt, ...) {}
  227.  
  228. Boolean audio_lib_capable()
  229. {
  230.         /* don't concern the user with an error message */
  231.         ALerrfunc originalErrorHandler = ALseterrorhandler(silentALerror);
  232.  
  233.         ALport tmpPort = ALopenport("test","w",0);
  234.         Boolean result = (Boolean)tmpPort;
  235.         if (tmpPort) ALcloseport(tmpPort);
  236.  
  237.         ALseterrorhandler(originalErrorHandler);
  238.  
  239.         return (result);
  240. }
  241.  
  242. /************************ for timing */
  243. clock_sec(s)
  244. float *s;
  245. {
  246. float  tmp1,tmp2;
  247. long   err;
  248. struct timeval tp;
  249. struct timezone tzp;
  250.  
  251.         err = gettimeofday(&tp,&tzp);
  252.  
  253.         tmp1 =  (float)(tp.tv_usec)/1000000.0;
  254.         tmp2 =  tp.tv_sec%10000;
  255.         *s = tmp1+tmp2;
  256.         return;
  257. } /******** end of 'for timing' */
  258.  
  259. void initCB_Main( Widget w, XtPointer client_data, XtPointer call_data)
  260. {
  261.     static float top_lt[] = {AMBIENT, 0.6, 0.6, 0.6,
  262.                            LCOLOR, .6, .6, .6,
  263.                            POSITION, -1.0, 0.0, 1.0, 0.0,
  264.                            LMNULL};
  265.     static float simple_lm[] = {AMBIENT, 0.6, 0.6, 0.6,
  266.                                 LOCALVIEWER, 0.0,
  267.                                 LMNULL};
  268.     static float paper[] = {EMISSION, 0.0, 0.0, 0.0,
  269.                     AMBIENT, 0.5, 0.5, 0.5,
  270.                     DIFFUSE, 0.6, 0.6, 0.6,
  271.                     SPECULAR, .3, .3, .3,
  272.                     SHININESS, 10.0,
  273.                     LMNULL};
  274.  
  275.    dooverlayview();
  276.    mapcolor(PUP_BLACK, 0, 0, 0);
  277.    mapcolor(PUP_WHITE, 255, 255, 255);
  278.    mapcolor(PUP_COLOR, 255, 0, 0);
  279.    dobookview();
  280. /* need to test to know when to set  subpixel(TRUE)  */
  281. /*
  282.    char version[12];
  283.  
  284.    gversion(version);
  285.     if (strncmp(version,"GL4DPI") != 0 && (getgdesc(GD_SUBPIXEL_LINE) ||
  286.         getgdesc(GD_SUBPIXEL_PNT) || getgdesc(GD_SUBPIXEL_POLY) ))
  287.                 subpixel(TRUE);
  288. */
  289.    initcolors();
  290.    mk_open_arrays();
  291.    mk_turn_arrays();
  292.    initshelves();
  293.  
  294.    lmdef(DEFMATERIAL, 1, 0, paper);
  295.    lmdef(DEFLIGHT, 1, 0, top_lt);
  296.    lmdef(DEFLMODEL, 1, 0, simple_lm);
  297.  
  298. /*(
  299.    Groupwin = -1;
  300.    Indexwin = -1;
  301.    ADwin = -1;
  302.    Rewin = -1;
  303. */
  304.    MW_Button1_mode = RELEASED;
  305.    MW_Button2_mode = RELEASED;
  306.  
  307. }
  308.  
  309. void overlayexposeCB_Main( Widget w, XtPointer client_data, XtPointer call_data)
  310. {
  311.    unhighlighticon();
  312. }
  313.  
  314. void exposeCB_Main( Widget w, XtPointer client_data, XtPointer call_data)
  315. {
  316.    GLXwinset (XtDisplay(w), XtWindow(w) );
  317.    drawscene(0);
  318. }
  319.  
  320. void resizeCB_Main( Widget w, XtPointer client_data, XtPointer call_data)
  321. {
  322.    GLXwinset (XtDisplay(w), XtWindow(w) );
  323.    reshapeviewport();
  324. }
  325.  
  326. int get_picked(short picbuf[], int hits)
  327. {
  328.    int i, j, c, num;
  329.    int picked;
  330.  
  331.    c = 0;
  332.    picked = 100;
  333.    for (i = 0; i < hits; i++)
  334.       {
  335.       num = picbuf[c++];
  336.       for (j = 0; j < num; j++)
  337.          {
  338.          if (picbuf[c] < 90)
  339.             picked = picbuf[c++];
  340.          else
  341.             c++;
  342.          }
  343.       }
  344.    return(picked);
  345. }
  346.  
  347. int do_picking()
  348. {
  349.    short picbuf[PICBUFSIZ];
  350.    int hits;
  351.    int picked;
  352.    int i;
  353.  
  354.    dobookview();
  355.    pick(picbuf, PICBUFSIZ);
  356.    dobookview();
  357.    initnames();
  358.    pickdrawscene(0);
  359.    hits = endpick(picbuf);
  360.    picked = get_picked(picbuf, hits);
  361.    dobookview();
  362.    return(picked);
  363. }
  364.  
  365. void open_new_book(Boolean motion, int picked)
  366. {
  367.    short picbuf[PICBUFSIZ];
  368.    int hits;
  369.    int i;
  370.    
  371.    if (picked >= 0 && picked < numberofbooks)
  372.       {
  373.       XtVaSetValues(CBbutton, XmNsensitive, TRUE, NULL);
  374.       currentbook = picked;
  375.       unhighlighticon();
  376.   dobookview();  /* unhighlight puts us in overlay window */
  377. /* total kludge */
  378.       curgroup = firstgroup;
  379.       i = 0;
  380.       while (i < picked && curgroup != NULL)
  381.          {
  382.          curgroup = curgroup->nextgrp;
  383.          i++;
  384.          }
  385.       if (curgroup == NULL)
  386.          curgroup = firstgroup;
  387.       leftpage = NULL;
  388.       middlepage = NULL;
  389.       rightpage = curgroup->firstpage;
  390.       thispage = rightpage;
  391. /* end of total kludge */
  392.          OPENBOOK = TRUE;
  393.          selected = -1;
  394.          prevselection = -1;
  395.          seliconptr = NULL;
  396.       if (motion)
  397.          {
  398.          initxflip(picked);
  399.          if (Audio)
  400.              system("playaiff /usr/lib/sounds/prosonus/musictags/tag2.aiff & ");
  401.          flipbook();
  402.          OPENBOOK = TRUE;
  403.          selected = -1;
  404.          prevselection = -1;
  405.          seliconptr = NULL;
  406.             /* stuff to open the book */
  407.          color_mult = 1.0;
  408.          openbook(0); /* 0 is rotate flag */
  409.          }
  410.       else 
  411.          {
  412.          OPENBOOK = TRUE;
  413.          selected = -1;
  414.          prevselection = -1;
  415.          seliconptr = NULL;
  416.          }
  417.  
  418.       drawscene(0);
  419.       }
  420. }
  421.  
  422. void inputCB_Main( Widget w, XtPointer client_data, XtPointer call_data)
  423. {
  424.    int picked;
  425.    int i;
  426.    int mx, my;
  427.    int ix, iy, xpagendx, ypagendx;
  428.    struct grptmpltstruct *group_to_move, *tmpgrp, *pgrp, *ngrp;
  429.    char *buffer;
  430.    int bytes;
  431.    KeySym key_sym;
  432.    XComposeStatus status;
  433.    GlxDrawCallbackStruct *glcall;
  434.    XKeyEvent *keyevent;
  435.  
  436. long wx, wy;
  437.  
  438.    glcall = (GlxDrawCallbackStruct *)call_data;
  439.    buffer = (char *)malloc(5);
  440.    for (i = 0; i < 5; i++)
  441.       buffer[i] = '\0';
  442.    dobookview();
  443.    switch(glcall->event->type)
  444.       {
  445.       case EnterNotify:
  446.          in_main_window = TRUE;
  447.       break;
  448.       case LeaveNotify:
  449.          in_main_window = FALSE;
  450.       break;
  451.       case KeyPress:
  452.          keyevent = (XKeyEvent *)glcall->event;
  453.          i = XLookupString(keyevent, buffer, 1, &key_sym, &status);
  454.          if (key_sym == XK_Alt_R || key_sym == XK_Alt_L)
  455.             {
  456.             AltKeyPressed = TRUE;
  457.             }
  458.       break;
  459.       case KeyRelease:
  460.          keyevent = (XKeyEvent *)glcall->event;
  461.          i = XLookupString(keyevent, buffer, 1, &key_sym, &status);
  462.          if (key_sym == XK_Alt_R || key_sym == XK_Alt_L)
  463.             {
  464.             AltKeyPressed = FALSE;
  465.             }
  466.       break;
  467.       case ButtonPress:
  468.       picked = do_picking();
  469.       switch (glcall->event->xbutton.button)
  470.          {
  471.          case Button1:
  472.             MW_Button1_mode = PRESSED;
  473.             if (OPENBOOK)
  474.                {
  475.                getsize(&winsize_x, &winsize_y);
  476.                mx = glcall->event->xbutton.x;
  477.                my = winsize_y - glcall->event->xbutton.y;
  478.                old_x = mx;
  479.                old_y = my;
  480.                if (picked < 0)
  481.                   {
  482.                   thispage = leftpage;
  483.                   side = BACK;
  484.                   picked = -picked - 1;
  485.                   }
  486.                else
  487.                   {
  488.                   thispage = rightpage;
  489.                   side = FRONT;
  490.                   }
  491.                if (thispage != NULL && picked >= 0 && picked < 80)
  492.                   {
  493.                   selected = picked;
  494.                   selectedpage = thispage;
  495.                   if (side == FRONT)
  496.                      tmpiconlist = thispage->fronticons;
  497.                   else
  498.                      tmpiconlist = thispage->backicons;
  499.                   i = 0;
  500.                   while (i != selected || (!tmpiconlist->ok && Hide))
  501.                      {
  502.                      if (!Hide || tmpiconlist->ok)
  503.                         i++;
  504.                      tmpiconlist = tmpiconlist->nexticon;
  505.                      }
  506.                   seliconptr = tmpiconlist;
  507.                      if (prevselection >= 0)
  508.                         {
  509.                         undrawselectedicon(prevpage, prevselection);
  510.                         }
  511.                      drawselectedicon(thispage, selected);
  512.                      prevpage = thispage;
  513. /* old way  
  514.                   if (selected != prevselection)
  515.                      {
  516.                      if (prevselection >= 0)
  517.                         {
  518.                         undrawselectedicon(prevpage, prevselection);
  519.                         }
  520.                      drawselectedicon(thispage, selected);
  521.                      prevpage = thispage;
  522.                      }
  523. */
  524.                   }
  525.                else if (picked == 80)
  526.                   {
  527.                   prevselection = -1;
  528.                   selected = -1;
  529.                   unhighlighticon();
  530.                   outlineleftedge();
  531.                   }
  532.                else if (picked == 81)
  533.                   {
  534.                   prevselection = -1;
  535.                   selected = -1;
  536.                   unhighlighticon();
  537.                   outlinerightedge();
  538.                   }
  539.                else if (picked > 81)
  540.                   {
  541.                   selected = -1;
  542.                   picked = -1;
  543.                   seliconptr = NULL;
  544.                   selectedpage = NULL;
  545.                   if (prevselection >= 0)
  546.                      {
  547.                      undrawselectedicon(prevpage, prevselection);
  548.                      }
  549.                   prevpage = thispage;
  550.                   }
  551. /* begin Gretch experiment */
  552.                if (picked == 80 && leftpage != NULL)
  553.                   {
  554.                   selectedpage = NULL;
  555.                   selected = -1;
  556.                   prevselection = -1;
  557.                   unhighlighticon();
  558.   dobookview();  /* unhighlight puts us in overlay window */
  559.                   leftpage->direction = -leftpage->direction;
  560.                   turnpage(0);
  561.                   }
  562.                else if (picked == 81 && rightpage != NULL)
  563.                   {
  564.                   selectedpage = NULL;
  565.                   selected = -1;
  566.                   prevselection = -1;
  567.                   unhighlighticon();
  568.   dobookview();  /* unhighlight puts us in overlay window */
  569.                   rightpage->direction = -rightpage->direction;
  570.                   turnpage(1);
  571.                   }
  572. /* end Gretch experiment */
  573.                }
  574.             else
  575.                {
  576.                selected = picked;
  577.                unhighlighticon();
  578.                if (picked >= 0 && picked < numberofbooks)
  579.                   highlightbookonshelf(picked);
  580.                }
  581.          break;
  582.          case Button2:
  583.             MW_Button2_mode = PRESSED;
  584.          break;
  585.          case Button3:
  586.          break;
  587.          }
  588.       break;
  589.       case ButtonRelease:
  590.       picked = do_picking();
  591.       switch (glcall->event->xbutton.button)
  592.          {
  593.          case Button1:
  594.             MW_Button1_mode = RELEASED;
  595.             if (!OPENBOOK)
  596.                {
  597.                if (MW_dragging)
  598.                   {
  599.                   MW_dragging = !MW_dragging;
  600.                   if (selected >= 0 && selected < numberofbooks)
  601.                      {
  602.                   /* find the pointer to the selected group
  603.                      and the prevselection/picked */
  604.                   if (picked > numberofgroups || picked < 0)
  605.                      picked = prevselection;
  606.                   if (picked >= 0 && picked != selected && picked != selected+1)
  607.                      {
  608.                      Change = TRUE;
  609.                      tmpgrp = firstgroup;
  610.                      for (i = 0; i < selected; i++)
  611.                         tmpgrp = tmpgrp->nextgrp;
  612.                      group_to_move = tmpgrp;
  613.                      tmpgrp = firstgroup;
  614.                      for (i = 0; i < picked; i++)
  615.                         tmpgrp = tmpgrp->nextgrp;
  616.                      /* take the selected group out of the linked list */
  617.                      pgrp = group_to_move->prevgrp;
  618.                      ngrp = group_to_move->nextgrp;
  619.                      if (pgrp != NULL)
  620.                         pgrp->nextgrp = ngrp;
  621.                      else
  622.                         firstgroup = ngrp;
  623.                      if (ngrp != NULL)
  624.                         ngrp->prevgrp = pgrp;
  625.                      else
  626.                         lastgroup = pgrp;
  627.                      /* add the selected group in front of the picked/
  628.                         prevselection group */
  629.                      pgrp = tmpgrp->prevgrp;
  630.                      ngrp = tmpgrp->nextgrp;
  631.                      group_to_move->prevgrp = pgrp;
  632.                      group_to_move->nextgrp = tmpgrp;
  633.                      tmpgrp->prevgrp = group_to_move;
  634.                      if (pgrp != NULL)
  635.                         pgrp->nextgrp = group_to_move;
  636.                      else
  637.                         firstgroup = group_to_move;
  638.                      drawscene(0);
  639.                      }
  640.                   unhighlighticon();
  641.                   if (picked >=0 && picked < numberofbooks)
  642.                      {
  643.                      if (selected < picked)
  644.                         highlightbookonshelf(picked-1);
  645.                      else
  646.                         highlightbookonshelf(picked);
  647.                      }
  648.                      }
  649.                   }
  650.                else
  651.                   open_new_book(MOTION, picked);
  652.                }
  653.             else  /* a book is open */
  654.                {
  655. #ifdef DEBUG
  656.                if (picked == 80 && leftpage != NULL)
  657.                   {
  658.                   selectedpage = NULL;
  659.                   selected = -1;
  660.                   prevselection = -1;
  661.                   unhighlighticon();
  662.   dobookview();  /* unhighlight puts us in overlay window */
  663.                   leftpage->direction = -leftpage->direction;
  664.                   turnpage(0);
  665.                   }
  666.                else if (picked == 81 && rightpage != NULL)
  667.                   {
  668.                   selectedpage = NULL;
  669.                   selected = -1;
  670.                   prevselection = -1;
  671.                   unhighlighticon();
  672.   dobookview();  /* unhighlight puts us in overlay window */
  673.                   rightpage->direction = -rightpage->direction;
  674.                   turnpage(1);
  675.                   }
  676. #endif
  677.            /*    else */ if (MW_dragging)
  678.                   {
  679.                   MW_dragging = FALSE;
  680.                   if (in_main_window)
  681.                      {
  682.                   if (xpagendx != -1 && ypagendx != -1)
  683.                      {
  684.                      if (curgroup->nameptr == find_keyword("Master Index"))
  685.                         {
  686.                         sprintf(msgstring, "Icons in this book can not be moved.");
  687.                         popup_Message();
  688.                         }
  689.                      else
  690.                         {
  691. #ifdef DEBUG
  692. if (seliconptr == NULL)
  693. printf(" it thinks i'm dragging    seliconptr = NULL \n");
  694. else
  695. {
  696. printf(" old page ndx %d %d    new %d %d \n", seliconptr->xposition_ndx, seliconptr->yposition_ndx, xpagendx, ypagendx);
  697. #endif
  698.                         if (xpagendx >= 0 && xpagendx < 5 &&
  699.                               ypagendx >= 0 && ypagendx < 4)
  700.                            {
  701.                            seliconptr->xposition_ndx = xpagendx;
  702.                            seliconptr->yposition_ndx = ypagendx;
  703.                            drawscene(0);
  704.                            }
  705. #ifdef DEBUG
  706. }
  707. #endif
  708.                         }
  709.                      }
  710.                      }
  711.                   else /* in_main_window == FALSE */
  712.                      {
  713.                      tmpiconlist = (struct iconstruct *)malloc(sizeof(struct iconstruct) );
  714.                      if (newgroupiconlist == NULL)
  715.                         newgroupiconlist = tmpiconlist;
  716.                      else
  717.                         newgrouplasticon->nexticon = tmpiconlist;
  718.                      if (newgrouplasticon != NULL)
  719.                         {
  720.                         tmpiconlist->xposition_ndx =
  721.                               newgrouplasticon->xposition_ndx+1;
  722.                         tmpiconlist->yposition_ndx =
  723.                               newgrouplasticon->yposition_ndx;
  724.                         }
  725.                      else
  726.                         {
  727.                         tmpiconlist->xposition_ndx = 0;
  728.                         tmpiconlist->yposition_ndx = 3;
  729.                         }
  730.                      if (tmpiconlist->xposition_ndx > 4)
  731.                         {
  732.                         tmpiconlist->xposition_ndx = 0;
  733.                         tmpiconlist->yposition_ndx--;
  734.                         }
  735.                      if (tmpiconlist->yposition_ndx < 0)
  736.                         tmpiconlist->yposition_ndx = 0;
  737.                      newgrouplasticon = tmpiconlist;
  738.                      tmpiconlist->iconptr = seliconptr->iconptr;
  739.                      tmpiconlist->ok = seliconptr->ok;
  740.                      tmpiconlist->nexticon = NULL;
  741.                      setgroupwin();
  742.                      drawgroupwin();
  743.                      }
  744.                   prevselection = selected;
  745.                   }
  746.                else 
  747.                   {
  748.                   if (picked < 0)
  749.                      {
  750.                      thispage = leftpage;
  751.                      side = BACK;
  752.                      picked = -picked - 1;
  753.                      }
  754.                   else
  755.                      {
  756.                      thispage = rightpage;
  757.                      side = FRONT;
  758.                      }
  759.                   gSide = side;
  760.                   /* times to use for testing for double click */
  761.                   clock_sec(&tmptime);
  762.                   elapsed_time = tmptime - click1;
  763.                   click1 = tmptime;
  764.                   if (elapsed_time <= DOUBLETIME)
  765.                      {
  766. /*
  767. printf(" double click \n");
  768. printf(" selected = %d prev = %d  \n", selected, prevselection);
  769. */
  770.                      if (selected == prevselection && selected >= 0)
  771.                         {
  772.                         unhighlighticon();
  773.   dobookview();  /* unhighlight puts us in overlay window */
  774.                         if (AltKeyPressed)
  775.                            {
  776.                            if (seliconptr->iconptr->alt_command != NULL)
  777.                               system(seliconptr->iconptr->alt_command);
  778.                            }
  779.                         else
  780.                            {
  781.                            if (seliconptr->iconptr->startstring != NULL)
  782.                               system(seliconptr->iconptr->startstring);
  783.                            }
  784.                         }
  785.                      }
  786. /*
  787.                   else
  788.                      {
  789. #ifdef DEBUG
  790. printf(" button release left mouse seliconptr = %d  \n",seliconptr);
  791. #endif
  792.                      }
  793. */
  794.                   prevselection = selected;
  795.                   }
  796.                }
  797.          break;
  798.          case Button2:
  799.             MW_Button2_mode = RELEASED;
  800.             if (!OPENBOOK)
  801.                open_new_book(NO_MOTION, picked);
  802.             else  /* a book is open */
  803.                {
  804.                /* click on left arrow, don't watch page turn */
  805.                if (picked == 80 && leftpage != NULL)   /* left side */
  806.                   {
  807.                   rightpage = leftpage;
  808.                   leftpage = leftpage->prevpage;
  809.                   rightpage->direction = 1;
  810.                   }
  811.                /* click on right arrow, don't watch page turn */
  812.                else if (picked == 81 && rightpage != NULL)   /* right side */
  813.                   {
  814.                   leftpage = rightpage;
  815.                   rightpage = rightpage->nextpage;
  816.                   leftpage->direction = -1;
  817.                   }
  818.                /*setcursor(0, 0, 0); */
  819.                drawscene(0);
  820.                }
  821.          break;
  822.          case Button3:
  823.                if (OPENBOOK)
  824.                   {
  825.                   selected = -1;
  826.                   prevselection = -1;
  827.                   seliconptr = NULL;
  828.                   close_book();
  829.                   drawscene(0);
  830.                   }
  831.          break;
  832.          }
  833.       break;
  834.       case MotionNotify:
  835.          if (!OPENBOOK)
  836.             {
  837.             picked = do_picking();
  838.             if (MW_Button1_mode && !ViewOnly)
  839.                {
  840.                if (selected >= 0 && selected < numberofbooks)
  841.                   {
  842.                   if (picked >= 0 && picked < numberofbooks && picked != prevmotion)
  843.                      {
  844.                      MW_dragging = TRUE;
  845.                      unhighlighticon();
  846.                      highlightbookonshelf(picked);
  847.                      shownewposition(picked);
  848.                      prevmotion = picked;
  849.                      }
  850.                   else if (picked < 0 || picked >= numberofbooks)
  851.                      {
  852.                      unhighlighticon();
  853.                      }
  854.                   }
  855.                }
  856.             else 
  857.                {
  858.                if (picked >= 0 && picked < numberofbooks)
  859.                   {
  860.                   if (picked != prevmotion)
  861.                      {
  862.                      unhighlighticon();
  863.                      highlightbookonshelf(picked);
  864.                      prevmotion = picked;
  865.                      }
  866.                   }
  867.                else
  868.                   {
  869.                   unhighlighticon();
  870.                   prevmotion = -1;
  871.                   }
  872.                }
  873.             }
  874.          else  /* a book is open */
  875.             {
  876.             if (MW_Button1_mode && !ViewOnly) /* left mouse is down */
  877.                {
  878. /*
  879. printf(" selected = %d  picked = %d\n",selected, picked);
  880.  
  881. */
  882.                if (selected != -1)
  883.                   {
  884.                ix = glcall->event->xbutton.x;
  885.                iy = winsize_y - glcall->event->xbutton.y;
  886. #ifdef DEBUG
  887. if (ix < 0 || ix > glcall->width || iy < 0 || iy > glcall->height)
  888. printf(" OUT OF WINDOW  \n");
  889. #endif
  890.                if (abs(old_x-ix) > 15 || abs(old_y - iy) > 15)
  891.                   {
  892.                MW_dragging = TRUE;
  893.                   old_x = ix;
  894.                   old_y = iy;
  895.                   if (closeup > 0 || (closeup == 0 && ix > winsize_x/2))
  896.                      {
  897.                      if (rightpage == NULL)
  898.                         {
  899.                         xpagendx = -1;
  900.                         ypagendx = -1;
  901.                         }
  902.                      else
  903.                         {
  904.                         findrightpagesquare(&xpagendx, &ypagendx);
  905.                         if (xpagendx < 0 || ypagendx < 0)
  906. {
  907.                            unhighlighticon();
  908.   dobookview();  /* unhighlight puts us in overlay window */
  909. }
  910.                         else
  911.                            if (xpagendx!=oldxpagendx || ypagendx!= oldypagendx)
  912.                               {
  913.                               oldxpagendx = xpagendx;
  914.                               oldypagendx = ypagendx;
  915.                               highlightsquare(FRONT, xpagendx, ypagendx);
  916.                               }
  917.                         }
  918.                      }
  919.                   else if (closeup < 0 || (closeup == 0 && ix < winsize_x/2))
  920.                      {
  921.                      if (leftpage == NULL)
  922.                         {
  923.                         xpagendx = -1;
  924.                         ypagendx = -1;
  925.                         }
  926.                      else
  927.                         {
  928.                         findleftpagesquare( &xpagendx, &ypagendx);
  929.                         if (xpagendx < 0 || ypagendx < 0)
  930.    {
  931.                            unhighlighticon();
  932.      dobookview();  /* unhighlight puts us in overlay window */
  933.    }
  934.                         else
  935.                            if (xpagendx!=oldxpagendx || ypagendx!= oldypagendx)
  936.                               {
  937.                               oldxpagendx = xpagendx;
  938.                               oldypagendx = ypagendx;
  939.                               highlightsquare(BACK, xpagendx, ypagendx);
  940.                               }
  941.                         }
  942.                      }
  943.                   }
  944.                   }
  945.                else if (picked == 80)
  946.                   {
  947.                   picked = do_picking();
  948.                   if (picked != 80)
  949.                      unhighlighticon();
  950.                   }
  951.                else if (picked == 81)
  952.                   {
  953.                   picked = do_picking();
  954.                   if (picked != 81)
  955.                      unhighlighticon();
  956.                   }
  957.                }
  958.             else if (!MW_Button2_mode)  /*a book is open, no buttons are down */
  959.                {
  960.                picked = do_picking();
  961. /*
  962.                mx = glcall->event->xbutton.x;
  963.                my = winsize_y - glcall->event->xbutton.y;
  964. */
  965.                if (picked < 0)
  966.                   {
  967.                   thispage = leftpage;
  968.                   side = BACK;
  969.                   picked = -1 - picked;
  970.                   }
  971.                else
  972.                   {
  973.                   thispage = rightpage;
  974.                   side = FRONT;
  975.                   }
  976.                if (thispage != NULL)
  977.                   {
  978. /*
  979.                   if (side == FRONT)
  980.                      curnumicons = thispage->frontnumicons;
  981.                   else if (side == BACK)
  982.                      curnumicons = thispage->backnumicons;
  983.                   else
  984.                      curnumicons = 0;
  985. */
  986.                   /* locate highlight the icon */
  987.                   if (picked < 0)
  988.                      {
  989.                      unhighlighticon();
  990.                      }
  991.                   else if (picked != prevmotion && picked < 21)
  992.                      {
  993.                      prevmotion = picked;
  994.                      highlighticon(picked, thispage, side);
  995.                      }
  996.                   else if (picked == 80)  /* left side */
  997.                      {
  998.                      prevmotion = -1;
  999.                      unhighlighticon();
  1000.                      outlineleftedge();
  1001.                      }
  1002.                   else if (picked == 81)  /* right side */
  1003.                      {
  1004.                      prevmotion = -1;
  1005.                      unhighlighticon();
  1006.                      outlinerightedge();
  1007.                      }
  1008.                   }
  1009.                else  /* thispage equals NULL here */
  1010.                   {
  1011.                   unhighlighticon();
  1012.                   prevmotion = -1;
  1013.                   }
  1014.                }
  1015.             }
  1016.       break;
  1017.       }
  1018. }
  1019.  
  1020. void menuCB_debug_index(Widget w, XtPointer client_data, XtPointer call_data)
  1021. {
  1022.    print_keywords();
  1023. }
  1024.  
  1025. void menuCB_debug_demos(Widget w, XtPointer client_data, XtPointer call_data)
  1026. {
  1027.    print_icons();
  1028. }
  1029.  
  1030. void menuCB_debug_books(Widget w, XtPointer client_data, XtPointer call_data)
  1031. {
  1032.    if (OPENBOOK)
  1033.       print_groups(curgroup);
  1034.    else
  1035.       print_groups(NULL);
  1036. }
  1037.  
  1038. void menuCB(Widget w, XtPointer client_data, XtPointer call_data)
  1039. {
  1040.    char *str;
  1041.  
  1042.    str = (char *)client_data;
  1043.          printf("menu option %s not implemented yet \n", str);
  1044. }
  1045.  
  1046. void menuCB_AddB(Widget w, XtPointer client_data, XtPointer call_data)
  1047. {
  1048.    if (numberofgroups > 0)
  1049.       {  
  1050.          Change = TRUE;
  1051.          initgpform();
  1052.          setgpform(NULL);
  1053.          initgroup();
  1054.          EditGroupFlag = 0;
  1055.          if (MotifGroupWin <= 0) {
  1056.            popup_CreateGroup();
  1057.            MotifGroupWin = 99;
  1058.            InterfaceWinOpen++ ;
  1059.          }
  1060.       }
  1061.    else
  1062.       {
  1063.       sprintf(msgstring, "Because this is an early version of the\ndemobook, you must read in a demobook file\nbefore you can create a new book.  Please\nchoose Open under the File Menu.");
  1064.       popup_Message();
  1065.       }
  1066. }
  1067.  
  1068. void menuCB_AddD(Widget w, XtPointer client_data, XtPointer call_data)
  1069. {
  1070.    if (numberofgroups > 0)
  1071.       {
  1072.       if (ADwin <= 0) {
  1073.         Change = TRUE;
  1074.         EditDemoFlag = 0;
  1075.         ADwin = initadwin();
  1076.         popup_AddDemo();
  1077.         InterfaceWinOpen++ ;
  1078.       }
  1079.       }
  1080.    else
  1081.       {
  1082.       sprintf(msgstring, "Because this is an early version of the\ndemobook, you must read in a demobook file\nbefore you can add more demos.  Please\nchoose Open under the File Menu.");
  1083.       popup_Message();
  1084.       }
  1085. }
  1086.  
  1087. void menuCB_Audio(Widget w, XtPointer client_data, XtPointer call_data)
  1088. {
  1089.    if (!Audio)
  1090.       Audio = audio_lib_capable();
  1091.    else
  1092.       Audio = !Audio;
  1093. }
  1094.  
  1095. void menuCB_DBHelp(Widget w, XtPointer client_data, XtPointer call_data)
  1096. {
  1097.    system("showcase -v $DEMOS/src/demos/demobook/help.show");
  1098. }
  1099.  
  1100. void menuCB_DHelp(Widget w, XtPointer client_data, XtPointer call_data)
  1101. {
  1102.    if (seliconptr == NULL)
  1103.       {
  1104.       sprintf(msgstring, "Please select a demo before asking for help on a\nspecific demo.  If you would like help on demobook,\nplease select Demobook from the help menu.");
  1105.       popup_Message();
  1106.       }
  1107.    else
  1108.       {
  1109.       if (seliconptr->iconptr->helpfile == NULL)
  1110.          {
  1111.          sprintf(msgstring, "Sorry, the demo you have selected, %s, does not have help.",seliconptr->iconptr->nameptr->string);
  1112.          popup_Message();
  1113.          }
  1114.       else
  1115.          {
  1116.          sprintf(msgstring, "showcase -v %s",seliconptr->iconptr->helpfile->name);
  1117.          system(msgstring);
  1118.          }
  1119.       }
  1120. }
  1121.  
  1122. void menuCB_BHelp(Widget w, XtPointer client_data, XtPointer call_data)
  1123. {
  1124.    if (curgroup == NULL)
  1125.       {
  1126.       sprintf(msgstring, "Please open a book before asking for help on a\nspecific book.  If you would like help on demobook,\nplease select Demobook from the help menu.");
  1127.       popup_Message();
  1128.       }
  1129.    else
  1130.       {
  1131.       if (curgroup->helpfile == NULL)
  1132.          {
  1133.          sprintf(msgstring, "Sorry, the book you have selected, %s, does not have help.",curgroup->nameptr->string);
  1134.          popup_Message();
  1135.          }
  1136.       else
  1137.          {
  1138. printf(" helpfile is %s  \n",curgroup->helpfile->name);
  1139.          sprintf(msgstring, "showcase -v %s",curgroup->helpfile->name);
  1140.          system(msgstring);
  1141.          }
  1142.       }
  1143. }
  1144.  
  1145. void menuCB_DelB(Widget w, XtPointer client_data, XtPointer call_data)
  1146. {
  1147.    if (curgroup != NULL)
  1148.       {
  1149.       if ( deletegroup(curgroup) )
  1150.          {
  1151.          Change = TRUE;
  1152.          drawscene(0);
  1153.          }
  1154.       DeleteGroupFlag = FALSE;
  1155.       }
  1156.    else
  1157.       {
  1158.       sprintf(msgstring, "To delete a book, open that book\nand then choose Delete Book from the\nBook Menu.");
  1159.       popup_Message();
  1160.       }
  1161. }
  1162.  
  1163. void menuCB_DelD(Widget w, XtPointer client_data, XtPointer call_data)
  1164. {
  1165.    if (selected >= 0)
  1166.       {
  1167.       Change = TRUE;
  1168.       deleteicon(curgroup, selected, gSide);
  1169.       drawscene(0);
  1170.       DeleteDemoFlag = FALSE;
  1171.       }
  1172.    else
  1173.       {
  1174.       sprintf(msgstring, "To delete a demo, select an icon on the\npage and then choose Delete Demo from\nthe Demos Menu.");
  1175.       popup_Message();
  1176.       }
  1177. }
  1178.  
  1179. void menuCB_Location(Widget w, XtPointer client_data, XtPointer call_data)
  1180. {
  1181. char command_line[256];
  1182.  
  1183.    if (selected >= 0)
  1184.       {
  1185.  
  1186.       /*
  1187.       Execute the find_location routine with the icon's "startstring".
  1188.       That routine strips out the demo's path from the startstring,
  1189.       and prints it out using xconfirm.
  1190.       */
  1191.       sprintf( command_line, "./find_location '%s", seliconptr->iconptr->startstring );
  1192.       strcat( command_line, "'" );
  1193.       system(command_line);
  1194.  
  1195.       }
  1196.    else
  1197.       {
  1198.       sprintf(msgstring, "To find the location of a program, select\nan icon on the page and then choose\nFindLocation from the Options Menu.");
  1199.       popup_Message();
  1200.       }
  1201. }
  1202.  
  1203.  
  1204. void menuCB_EditB(Widget w, XtPointer client_data, XtPointer call_data)
  1205. {
  1206.  
  1207.    long rslt;
  1208. #ifdef DEBUG
  1209. printf(" waht happens when I want to edit a group when the group window is open?? \n");
  1210. #endif
  1211.       if (curgroup != NULL)
  1212.          {
  1213.          if ((rslt = editgroup()) > 0)
  1214.             {
  1215.             Change = TRUE;
  1216.             EditGroupFlag = 1;
  1217.             if (MotifGroupWin <= 0) {
  1218.                popup_CreateGroup();
  1219.                MotifGroupWin = 99;
  1220.                InterfaceWinOpen++ ;
  1221.                }
  1222.             }
  1223.          else
  1224.             {
  1225.             sprintf(msgstring, "The Master Index is a special book and\ncannot be edited.  It contains all of the\ndemos in the demobook in alphabetical order.\nIf you want to add a demo to the book,\nuse the add demo feature under\nthe Demos menu.");
  1226.             popup_Message();
  1227.             }
  1228.          }
  1229.       else
  1230.          {
  1231.          sprintf(msgstring, "To edit a book, first make sure that no\nother books are open for editing (close\nthe book window).  Then open that\nbook and select Edit Book from\nthe Book Menu.");
  1232.          popup_Message();
  1233.          }
  1234. }
  1235.  
  1236. void menuCB_EditD(Widget w, XtPointer client_data, XtPointer call_data)
  1237. {
  1238.    if (ADwin <= 0) {
  1239.      if (selected >= 0) {
  1240.        Change = TRUE;
  1241.        EditDemoFlag = 1;
  1242.        ADwin = initadwin();
  1243.         create_AddDemo();
  1244.        popup_AddDemo();
  1245.        InterfaceWinOpen++ ;
  1246.      }
  1247.      else {
  1248.        sprintf(msgstring, "To edit demo information, please select\na demo by clicking on its icon before\nchoosing Edit Demo Info from the menu.\nTo add a new demo, choose Add Demo from\nthe Demos menu.");
  1249.        popup_Message();
  1250.      }
  1251.    }
  1252. }
  1253.  
  1254. /* fix_file_buttons: this sets up whether you can select buttons under
  1255.  * the File menu, specifically the Open and Append buttons.  You cannot
  1256.  * open another data file after the first file is read in; and you cannot
  1257.  * append to the file if you started demobook in View Only mode.
  1258.  */
  1259. void fix_file_buttons()
  1260. {
  1261. #ifdef DEBUG
  1262. printf(" in fix file_buttons \n");
  1263. #endif
  1264.    if (firstgroup == NULL)  /* if a file has NOT been read or specified */
  1265.       {                         /* you can only open, but not append, a file */
  1266.       XtVaSetValues(OpenButton, XmNsensitive, TRUE, NULL);
  1267.       XtVaSetValues(AppendButton, XmNsensitive, FALSE, NULL);
  1268.       }
  1269.    else             /* if a file has been read */
  1270.       {                         /* you can't open another file RATMAN */
  1271.       XtVaSetValues(OpenButton, XmNsensitive, FALSE, NULL);
  1272.       if (ViewOnly)             /* you cannot make changes in viewonly mode */
  1273.          XtVaSetValues(AppendButton, XmNsensitive, FALSE, NULL);
  1274.       else
  1275.          XtVaSetValues(AppendButton, XmNsensitive, TRUE, NULL);
  1276.       }
  1277. #ifdef DEBUG
  1278. printf(" leaving fix file_buttons \n\n");
  1279. #endif
  1280. }
  1281.  
  1282. /* fix_zoom_buttons:  this determines if you can choose on the zoom buttons.
  1283.  * if you've zoomed in a direction, you can't keep zooming that way more
  1284.  * than the first time.
  1285.  */
  1286. void fix_zoom_buttons()
  1287. {
  1288.    if (closeup == -1)   /* meaning we zoomed left */
  1289.       {
  1290.       XtVaSetValues(ZLbutton, XmNsensitive, FALSE, NULL);
  1291.       XtVaSetValues(ZRbutton, XmNsensitive, TRUE, NULL);
  1292.       XtVaSetValues(ZObutton, XmNsensitive, TRUE, NULL);
  1293.       }
  1294.    else if (closeup == 0)  /* meaning we zoomed out */
  1295.       {
  1296.       XtVaSetValues(ZObutton, XmNsensitive, FALSE, NULL);
  1297.       XtVaSetValues(ZRbutton, XmNsensitive, TRUE, NULL);
  1298.       XtVaSetValues(ZLbutton, XmNsensitive, TRUE, NULL);
  1299.       }
  1300.    else if (closeup == 1) /* meaning we zoomed right */
  1301.       {
  1302.       XtVaSetValues(ZRbutton, XmNsensitive, FALSE, NULL);
  1303.       XtVaSetValues(ZLbutton, XmNsensitive, TRUE, NULL);
  1304.       XtVaSetValues(ZObutton, XmNsensitive, TRUE, NULL);
  1305.       }
  1306. }
  1307.  
  1308. void menuCB_ZoomLeft(Widget w, XtPointer client_data, XtPointer call_data)
  1309. {
  1310.    closeup = -1;
  1311.    fix_zoom_buttons();
  1312.    dobookview();
  1313.    drawscene(0);
  1314. }
  1315.  
  1316. void menuCB_ZoomRight(Widget w, XtPointer client_data, XtPointer call_data)
  1317. {
  1318.    closeup = 1;
  1319.    fix_zoom_buttons();
  1320.    dobookview();
  1321.    drawscene(0);
  1322. }
  1323.  
  1324. void menuCB_ZoomOut(Widget w, XtPointer client_data, XtPointer call_data)
  1325. {
  1326.    closeup = 0;
  1327.    fix_zoom_buttons();
  1328.    dobookview();
  1329.    drawscene(0);
  1330. }
  1331.  
  1332. void menuCB_CloseBook(Widget w, XtPointer client_data, XtPointer call_data)
  1333. {
  1334.    XtVaSetValues(CBbutton, XmNsensitive, FALSE, NULL);
  1335.    selected = -1;
  1336.    prevselection = -1;
  1337.    seliconptr = NULL;
  1338.    close_book();
  1339.    drawscene(0);
  1340.    fix_zoom_buttons();
  1341. }
  1342.  
  1343. void menuCB_Hide(Widget w, XtPointer client_data, XtPointer call_data)
  1344. {
  1345.    Hide = !Hide;
  1346.    setup_all_groups();
  1347.    if (OPENBOOK)
  1348.       {
  1349.       if (leftpage != NULL)
  1350.          rightpage = leftpage->nextpage;
  1351.       }
  1352.    drawscene(0);
  1353. }
  1354.  
  1355. void menuCB_Index(Widget w, XtPointer client_data, XtPointer call_data)
  1356. {
  1357.    popup_Index();
  1358. }
  1359.  
  1360. void menuCB_Append(Widget w, XtPointer client_data, XtPointer call_data)
  1361. {
  1362.    FileMode = 1;  /* Read File */
  1363.       if (RDwin <= 0)
  1364.          {
  1365.          UxPopupInterface(BookFile, no_grab);
  1366.          RDwin = 99;
  1367.          InterfaceWinOpen++ ;
  1368.          }
  1369. }
  1370.  
  1371. void menuCB_Open(Widget w, XtPointer client_data, XtPointer call_data)
  1372. {
  1373.    FileMode = 1;  /* Read File */
  1374.    if (firstgroup == NULL) 
  1375.       {
  1376.       if (RDwin <= 0)
  1377.          {
  1378.          UxPopupInterface(BookFile, no_grab);
  1379.          RDwin = 99;
  1380.          InterfaceWinOpen++ ;
  1381.          }
  1382.       }
  1383.    else
  1384.       {
  1385.       sprintf(msgstring, "Because this is an early version of the\ndemobook, you must restart the program\nto open a different demobook file.");
  1386.       popup_Message();
  1387.       }
  1388. }
  1389.  
  1390. void menuCB_Save(Widget w, XtPointer client_data, XtPointer call_data)
  1391. {
  1392.    Change = FALSE;
  1393.    if (numberofgroups > 0)
  1394.       {
  1395.  
  1396.       if (FileName == NULL)
  1397. /*                We should not get here. */
  1398.          printf("Error:  Book FileName is NULL.  Nothing will be saved.\n");
  1399.       else
  1400.          {
  1401.          DialogType = 7;
  1402.          popup_Question();
  1403.          handleMessageEvents();
  1404.          }
  1405.       }
  1406.    else
  1407.       {
  1408.       sprintf(msgstring, "\nThis demobook file is empty.  Nothing will be saved.\n");
  1409.       popup_Message();
  1410.       }
  1411. }
  1412.  
  1413. void menuCB_SaveAs_binary(Widget w, XtPointer client_data, XtPointer call_data)
  1414. {
  1415.    Change = FALSE;
  1416.    ASCII = FALSE;
  1417.    FileMode = 2;  /* Write File */
  1418.    if (numberofgroups > 0)
  1419.       {
  1420.       if (RDwin <= 0) {
  1421.         UxPopupInterface(BookFile, no_grab);
  1422.         RDwin = 99;
  1423.         InterfaceWinOpen++ ;
  1424.       }
  1425.       }
  1426.    else
  1427.       {
  1428.       sprintf(msgstring, "\nThis demobook file is empty.  Nothing will be saved.\n");
  1429.       popup_Message();
  1430.       }
  1431. }
  1432.  
  1433. void menuCB_SaveAs_ascii(Widget w, XtPointer client_data, XtPointer call_data)
  1434. {
  1435.    Change = FALSE;
  1436.    ASCII = TRUE;
  1437.    FileMode = 2;  /* Write File */
  1438.    if (numberofgroups > 0)
  1439.       {
  1440.       if (RDwin <= 0) {
  1441.         UxPopupInterface(BookFile, no_grab);
  1442.         RDwin = 99;
  1443.         InterfaceWinOpen++ ;
  1444.       }
  1445.       }
  1446.    else
  1447.       {
  1448.       sprintf(msgstring, "\nThis demobook file is empty.  Nothing will be saved.\n");
  1449.       popup_Message();
  1450.       }
  1451. }
  1452.  
  1453. void menuCB_Tar(Widget w, XtPointer client_data, XtPointer call_data)
  1454. {
  1455. /* error checking that I will do again after I can use popup_Message()
  1456.    if (FileName == NULL)
  1457.       {
  1458.       sprintf(msgstring, "You must read in a demobook file before\nyou can create a tape.  Please choose\nOpen under the File Menu.");
  1459.       popup_Message();
  1460.       }
  1461.    else if (numberofgroups <= 0)
  1462.       {
  1463.       sprintf(msgstring, "\nThis demobook is empty.  No tape will be created.\n");
  1464.       popup_Message();
  1465.       }
  1466.    else
  1467. */
  1468.       tar_files();
  1469. }
  1470.  
  1471. void menuCB_Quit(Widget w, XtPointer client_data, XtPointer call_data)
  1472. {
  1473.    if (Change)
  1474.       {
  1475.       popup_Quit();
  1476.       }
  1477.    else
  1478.       {
  1479.       exit(1);
  1480.       }
  1481. }
  1482.  
  1483. /* create_menu_widget:  creates menus for DemoBook.  Parent is
  1484.  * topform.
  1485. */
  1486. Widget create_menu_widget (Widget parent)
  1487. {
  1488.    Widget menubar, menupane, submenupane, helpwidget;
  1489.    Widget button, cascade;
  1490.    Arg wargs[10];
  1491.    int n;
  1492.    XmStringCharSet charset = (XmStringCharSet) XmSTRING_DEFAULT_CHARSET;
  1493.                                 /* used to set up XmStrings */
  1494.  
  1495. /* create the entire top menu bar */
  1496.        n = 0;
  1497.     XtSetArg (wargs[n], XmNtopAttachment, XmATTACH_FORM); n++;
  1498.     XtSetArg (wargs[n], XmNrightAttachment, XmATTACH_FORM); n++;
  1499.     XtSetArg (wargs[n], XmNleftAttachment, XmATTACH_FORM); n++;
  1500.     menubar = XmCreateMenuBar (parent, "menubar", wargs, n);
  1501.  
  1502. /* File placeholder for File menu */
  1503.    n = 0;
  1504.    menupane = XmCreatePulldownMenu (menubar, "filepane", wargs, n);
  1505.  
  1506. #ifdef HideMenu
  1507. /* Open selection from File menu */
  1508.    n = 0;
  1509.    OpenButton = XmCreatePushButton(menupane, "OpenButton", wargs, n);
  1510.    XtAddCallback(OpenButton, XmNactivateCallback, menuCB_Open, "Open");
  1511.    XtManageChild(OpenButton);
  1512. #endif
  1513.  
  1514. #ifdef HideMenu
  1515. /* Append selection from File menu */
  1516.    n = 0;
  1517.    AppendButton = XmCreatePushButton(menupane, "AppendButton", wargs, n);
  1518.    XtAddCallback(AppendButton, XmNactivateCallback, menuCB_Append, "Append");
  1519.    XtManageChild(AppendButton);
  1520.  
  1521.    fix_file_buttons();  /* determine sensitivity of Append and Open buttons */
  1522. #endif
  1523.  
  1524. #ifdef HideSAVEMenu
  1525. /* Save selection from File menu */
  1526.    n = 0;
  1527.    button = XmCreatePushButton(menupane, "SaveButton", wargs, n);
  1528.    XtAddCallback(button, XmNactivateCallback, menuCB_Save, "Save");
  1529.    XtManageChild(button);
  1530.  
  1531. /* Save As  placeholder for Save As menu from File menu.  This is a sub menu. */
  1532.    n = 0;
  1533.    submenupane = XmCreatePulldownMenu (menupane, "saveaspane", wargs, n);
  1534.  
  1535. /* Binary button from Save As selection */
  1536.    n = 0;
  1537.    button = XmCreatePushButton(submenupane, "BinaryButton", wargs, n);
  1538.    XtAddCallback(button, XmNactivateCallback, menuCB_SaveAs_binary, "Save As");
  1539.    XtManageChild(button);
  1540.  
  1541. /* Ascii button from Save As selection */
  1542.    n = 0;
  1543.    button = XmCreatePushButton(submenupane, "AsciiButton", wargs, n);
  1544.    XtAddCallback(button, XmNactivateCallback, menuCB_SaveAs_ascii, "Save As");
  1545.    XtManageChild(button);
  1546.  
  1547. /* Save As selection from File menu */
  1548.    n = 0;
  1549.    XtSetArg (wargs[n], XmNsubMenuId, submenupane);  n++;
  1550.    cascade = XmCreateCascadeButton (menupane, "SaveAsButton", wargs, n);
  1551.    XtManageChild (cascade);
  1552.  
  1553. /* Michelle had this commented out.
  1554.    n = 0;
  1555.    button = XmCreatePushButton(menupane, "Save As", wargs, n);
  1556.    XtAddCallback(button, XmNactivateCallback, menuCB_SaveAs, "Save As");
  1557.    XtManageChild(button);
  1558. */
  1559. #endif
  1560.  
  1561. #ifdef BROKE
  1562. /* Create Tape selection from File menu */
  1563.    n = 0;
  1564.    button = XmCreatePushButton(menupane, "CreateTapeButton", wargs, n);
  1565.    XtAddCallback(button, XmNactivateCallback, menuCB_Tar, "Create a Tape");
  1566.    XtManageChild(button);
  1567. #endif
  1568.  
  1569. /* Seperator on File menu */
  1570.    n = 0;
  1571.    button = XmCreateSeparator(menupane, "sep", wargs, n);
  1572.    XtManageChild(button);
  1573.  
  1574. /* Quit selection on File menu */
  1575.    n = 0;
  1576.    button = XmCreatePushButton(menupane, "QuitButton", wargs, n);
  1577.    XtAddCallback(button, XmNactivateCallback, menuCB_Quit, "Quit");
  1578.    XtManageChild(button);
  1579.  
  1580. /* The File menu on the menu bar */
  1581.    n = 0;
  1582.    XtSetArg (wargs[n], XmNsubMenuId, menupane);  n++;
  1583.    cascade = XmCreateCascadeButton (menubar, "FilePane", wargs, n);
  1584.    XtManageChild (cascade);
  1585.  
  1586.    if (!ViewOnly)       /* You don't get Demos or Books in viewonly mode */
  1587.       {
  1588. /* Demos placeholder for Demos menu */
  1589.    n = 0;
  1590.    menupane = XmCreatePulldownMenu (menubar, "demospane", wargs, n);
  1591.  
  1592. /* Add Demo selection on Demos menu */
  1593.    n = 0;
  1594.    button = XmCreatePushButton(menupane, "AddDemoButton", wargs, n);
  1595.    XtAddCallback(button, XmNactivateCallback, menuCB_AddD, "Add Demo");
  1596.    XtManageChild(button);
  1597.  
  1598. /* Delete Demo selection on Demos menu */
  1599.    n = 0;
  1600.    button = XmCreatePushButton(menupane, "DeleteDemoButton", wargs, n);
  1601.    XtAddCallback(button, XmNactivateCallback, menuCB_DelD, "Delete Demo");
  1602.    XtManageChild(button);
  1603.  
  1604. /* Edit Demo selection on Demos menu */
  1605.    n = 0;
  1606.    button = XmCreatePushButton(menupane, "EditDemoButton", wargs, n);
  1607.    XtAddCallback(button, XmNactivateCallback, menuCB_EditD, "Edit Demo Info");
  1608.    XtManageChild(button);
  1609.  
  1610. /* Demos menu */
  1611. #ifdef HideMenu
  1612.    n = 0;
  1613.    XtSetArg (wargs[n], XmNsubMenuId, menupane);  n++;
  1614.    cascade = XmCreateCascadeButton (menubar, "DemosPane", wargs, n);
  1615.    XtManageChild (cascade);
  1616. #endif
  1617.  
  1618. /* Books placeholder for Books menu */
  1619.    n = 0;
  1620.    menupane = XmCreatePulldownMenu (menubar, "bookspane", wargs, n);
  1621.  
  1622. /* Add Book selection in Books menu */
  1623.    n = 0;
  1624.    button = XmCreatePushButton(menupane, "AddButton", wargs, n);
  1625.    XtAddCallback(button, XmNactivateCallback, menuCB_AddB, "Add Book");
  1626.    XtManageChild(button);
  1627.  
  1628. /* Delete Book selection in Books menu */
  1629.    n = 0;
  1630.    button = XmCreatePushButton(menupane, "DeleteButton", wargs, n);
  1631.    XtAddCallback(button, XmNactivateCallback, menuCB_DelB, "Delete Book");
  1632.    XtManageChild(button);
  1633.  
  1634. /* Edit Book selection in Books menu */
  1635.    n = 0;
  1636.    button = XmCreatePushButton(menupane, "EditButton", wargs, n);
  1637.    XtAddCallback(button, XmNactivateCallback, menuCB_EditB, "Edit Book Info");
  1638.    XtManageChild(button);
  1639.  
  1640. /* Book Menu */
  1641. #ifdef HideMenu
  1642.    n = 0;
  1643.    XtSetArg (wargs[n], XmNsubMenuId, menupane);  n++;
  1644.    cascade = XmCreateCascadeButton (menubar, "BooksPane", wargs, n);
  1645.    XtManageChild (cascade);
  1646. #endif
  1647.       }
  1648.  
  1649. /* Options placeholder for Options menu.  You always get this menu. */
  1650.    n = 0;
  1651.    menupane = XmCreatePulldownMenu (menubar, "optionspane", wargs, n);
  1652.  
  1653. /* Show All Demos selection in Options menu */
  1654.    n = 0;
  1655.    if (Hide)  /* want to hide demos that are not present, disable toggle */
  1656.       XtSetArg (wargs[n], XmNset, FALSE);
  1657.    else
  1658.       XtSetArg (wargs[n], XmNset, TRUE);
  1659.    n++;
  1660.    button = XmCreateToggleButton(menupane, "Show All Demos", wargs, n);
  1661.    XtAddCallback(button, XmNvalueChangedCallback, menuCB_Hide, "Show All Demos");
  1662.    XtManageChild(button);
  1663.  
  1664. /* Close Book selection in Options menu */
  1665.    n = 0;
  1666.    if (OPENBOOK)                /* only available if book open */
  1667.        XtSetArg (wargs[n], XmNsensitive, TRUE);
  1668.    else
  1669.        XtSetArg (wargs[n], XmNsensitive, FALSE);
  1670.    n++;
  1671.    CBbutton = XmCreatePushButton(menupane, "CloseButton", wargs, n);
  1672.    XtAddCallback(CBbutton, XmNactivateCallback, menuCB_CloseBook, "Close Book");
  1673.    XtManageChild(CBbutton);
  1674.  
  1675. /* Ratman added this */
  1676.    n = 0;
  1677.    button = XmCreatePushButton(menupane, "FindLocation", wargs, n);
  1678.    XtAddCallback(button, XmNactivateCallback, menuCB_Location, "FindLocation");
  1679.    XtManageChild(button);
  1680.  
  1681. /* Zoom Left selection */
  1682.    n = 0;
  1683.    ZLbutton = XmCreatePushButton(menupane, "ZLeftButton", wargs, n);
  1684.    XtAddCallback(ZLbutton, XmNactivateCallback, menuCB_ZoomLeft, "Zoom Left");
  1685.    XtManageChild(ZLbutton);
  1686.  
  1687. /* Zoom Right Selection */
  1688.    n = 0;
  1689.    ZRbutton = XmCreatePushButton(menupane, "ZRightButton", wargs, n);
  1690.    XtAddCallback(ZRbutton, XmNactivateCallback, menuCB_ZoomRight, "Zoom Right");
  1691.    XtManageChild(ZRbutton);
  1692.  
  1693. /* Zoom Out */
  1694.    n = 0;
  1695.    ZObutton = XmCreatePushButton(menupane, "ZOutButton", wargs, n);
  1696.    XtAddCallback(ZObutton, XmNactivateCallback, menuCB_ZoomOut, "Zoom Out");
  1697.    XtManageChild(ZObutton);
  1698.  
  1699.    fix_zoom_buttons();
  1700.  
  1701. /* Michelle left this commented out.
  1702.    if (audio_lib_capable())
  1703.       {
  1704.    n = 0;
  1705.    if (Audio)
  1706.       XtSetArg (wargs[n], XmNset, TRUE);
  1707.    else
  1708.       XtSetArg (wargs[n], XmNset, FALSE);
  1709.    n++;
  1710.    button = XmCreateToggleButton(menupane, "Audio", wargs, n);
  1711.    XtAddCallback(button, XmNvalueChangedCallback, menuCB_Audio, "Audio");
  1712.    XtManageChild(button);
  1713.       }
  1714. */
  1715.  
  1716. /* Options placeholder for Options menu */
  1717.    n = 0;
  1718.    XtSetArg (wargs[n], XmNsubMenuId, menupane);  n++;
  1719.    cascade = XmCreateCascadeButton (menubar, "OptionsPane", wargs, n);
  1720.    XtManageChild (cascade);
  1721.  
  1722. #ifdef DEBUG  /* we only use this for debugging purposes */
  1723.    n = 0;
  1724.    menupane = XmCreatePulldownMenu (menubar, "debugpane", wargs, n);
  1725.  
  1726.    n = 0;
  1727.    button = XmCreatePushButton(menupane, "print demos", wargs, n);
  1728.    XtAddCallback(button, XmNactivateCallback, menuCB_debug_demos, NULL);
  1729.    XtManageChild(button);
  1730.  
  1731.    n = 0;
  1732.    button = XmCreatePushButton(menupane, "print books", wargs, n);
  1733.    XtAddCallback(button, XmNactivateCallback, menuCB_debug_books, NULL);
  1734.    XtManageChild(button);
  1735.  
  1736.    n = 0;
  1737.    button = XmCreatePushButton(menupane, "print index", wargs, n);
  1738.    XtAddCallback(button, XmNactivateCallback, menuCB_debug_index, NULL);
  1739.    XtManageChild(button);
  1740.  
  1741.    n = 0;
  1742.    XtSetArg (wargs[n], XmNsubMenuId, menupane);  n++;
  1743.    cascade = XmCreateCascadeButton (menubar, "Debug", wargs, n);
  1744.    XtManageChild (cascade); 
  1745. #endif
  1746.  
  1747. /* Help placeholder for Help menu */
  1748.    n = 0;
  1749.    menupane = XmCreatePulldownMenu (menubar, "helppane", wargs, n);
  1750.  
  1751. /* Demobook selection */
  1752. #ifdef HideMenu
  1753.    n = 0;
  1754.    button = XmCreatePushButton(menupane, "DemobookButton", wargs, n);
  1755.    XtAddCallback(button, XmNactivateCallback, menuCB_DBHelp, "Demobook");
  1756.    XtManageChild(button);
  1757. #endif
  1758.  
  1759. /* Demo selection */
  1760.    n = 0;
  1761.    button = XmCreatePushButton(menupane, "DemoButton", wargs, n);
  1762.    XtAddCallback(button, XmNactivateCallback, menuCB_DHelp, "Demobook");
  1763.    XtManageChild(button);
  1764.  
  1765. /* Book selection */
  1766. #ifdef HideMenu
  1767.    n = 0;
  1768.    button = XmCreatePushButton(menupane, "BookButton", wargs, n);
  1769.    XtAddCallback(button, XmNactivateCallback, menuCB_BHelp, "Demobook");
  1770.    XtManageChild(button);
  1771. #endif
  1772.  
  1773. /* Index selection */
  1774. #ifdef HideMenu
  1775.    n = 0;
  1776.    button = XmCreatePushButton(menupane, "IndexButton", wargs, n);
  1777.    XtAddCallback(button, XmNactivateCallback, menuCB_Index, "Index");
  1778.    XtManageChild(button);
  1779. #endif
  1780.  
  1781. /* Help menu */
  1782.    n = 0;
  1783.    XtSetArg (wargs[n], XmNsubMenuId, menupane);  n++;
  1784.    cascade = XmCreateCascadeButton (menubar, "Help", wargs, n);
  1785.    XtManageChild (cascade);
  1786.  
  1787.    n = 0;
  1788.    XtSetArg (wargs[n], XmNmenuHelpWidget, cascade);  n++;
  1789.    XtSetValues (menubar, wargs, n);
  1790.    XtManageChild (menubar);
  1791.  
  1792.    return(menubar);
  1793. }
  1794.  
  1795. /* create_widgets: create the menu widgets */
  1796. void create_widgets(Widget parent)      /* parent is really DBtoplevel */
  1797. {
  1798.    Arg wargs[10];
  1799.    int n;
  1800.    Widget topform, menu, GLframe;
  1801.    XtTranslations mytrans;
  1802.  
  1803.    n = 0;
  1804.    topform = XtCreateManagedWidget(
  1805.                 "DemobookTopForm", /* arbitrary widget name */
  1806.                 xmFormWidgetClass,      /* form widget class */
  1807.                 parent, /* parent widget */
  1808.                 wargs,  /* argument list */
  1809.                 n);     /* number of arguments */
  1810.    menu = create_menu_widget(topform);  /* menus are children of topform */
  1811.  
  1812. #ifdef DEBUG
  1813.    XSynchronize(XtDisplay(topform),TRUE);
  1814. #endif
  1815.  
  1816.    n = 0;
  1817.    XtSetArg(wargs[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
  1818.    XtSetArg(wargs[n],XmNtopWidget, menu); n++;
  1819.    XtSetArg(wargs[n], XmNbottomAttachment, XmATTACH_FORM); n++;
  1820.    XtSetArg(wargs[n], XmNleftAttachment, XmATTACH_FORM); n++;
  1821.    XtSetArg(wargs[n], XmNrightAttachment, XmATTACH_FORM); n++;
  1822.    GLframe = XtCreateManagedWidget("GLframe",
  1823.            xmFrameWidgetClass, topform, wargs, n);
  1824.   
  1825.    mytrans = XtParseTranslationTable(defaultTranslations);
  1826.    n = 0;
  1827.    if (use_pups)
  1828.       glxconfig_Main[3].buffer = GLX_POPUP;
  1829.    XtSetArg(wargs[n], GlxNglxConfig, glxconfig_Main); n++;
  1830.    XtSetArg(wargs[n], use_pups?GlxNusePopup:GlxNuseOverlay, TRUE); n++;
  1831.    MainGL = GlxCreateMDraw(GLframe, "glwidget", wargs, n);
  1832.    XtAddCallback( MainGL, GlxNginitCallback, initCB_Main, NULL);
  1833.    XtAddCallback( MainGL, GlxNexposeCallback, exposeCB_Main, NULL);
  1834.    XtAddCallback( MainGL, GlxNresizeCallback, resizeCB_Main, NULL);
  1835.    XtAddCallback( MainGL, GlxNinputCallback, inputCB_Main, NULL);
  1836.    XtAddCallback( MainGL,
  1837.     use_pups?GlxNpopupExposeCallback:GlxNoverlayExposeCallback,
  1838.     overlayexposeCB_Main, NULL);
  1839.    XtManageChild(MainGL);
  1840.    XtAugmentTranslations(MainGL, mytrans);
  1841. }
  1842.  
  1843.  
  1844. main(argc,argv)
  1845. int argc;
  1846. char **argv;
  1847. {
  1848.    int i;
  1849.                                 /* set everything to null at beginning */
  1850.    Boolean BadCommand = FALSE;  /* bad command line option flag */
  1851.  
  1852.    Change = FALSE;
  1853.    FileName = NULL;             /* this is the name of the data file */
  1854.    leftpage = NULL;
  1855.    rightpage = NULL;
  1856.    HeadGrpChar = NULL;
  1857.    TailGrpChar = NULL;
  1858.    HeadChar = NULL;
  1859.    TailChar = NULL;
  1860.    headfile = NULL;
  1861.    numberoficons = 0;
  1862.    numberofgroups = 0;
  1863.    prevselection = -1;
  1864.    lastvertex = 0;
  1865.    selected = -1;
  1866.    currentbook = -1;
  1867.    numberofbooks = 0;
  1868.    color_mult = 1.0;
  1869.    Hide = FALSE;                /* hide demos that aren't present */
  1870.    Audio = FALSE;               /* is audio flag set? */
  1871.    msgstring = (char *)malloc( sizeof(char) * 500);/* immediately malloc space
  1872. */
  1873.                                                /* for the mesg string */
  1874.    firsticon == NULL;
  1875.    lasticon == NULL;
  1876.    firstgroup = NULL;           /* determines if file was read in ? */
  1877.    lastgroup = NULL;
  1878.    demoenv = NULL;              /* where do we look for demos? */
  1879.    xenv = NULL;
  1880.    sbenv = NULL;
  1881.    ViewOnly = FALSE;            /* won't let you change anything in viewonly mode */
  1882.  
  1883. #ifdef DEBUG
  1884. printf(" about to do a getgdesc \n");
  1885. #endif
  1886.  
  1887.    if (getgdesc(GD_BITS_OVER_SNG_CMODE) < 2)    /* first find out if we can use
  1888. */
  1889.       use_pups = TRUE;                          /* overlay or popup */
  1890. #ifdef DEBUG
  1891. printf(" did a getgdesc  and survived\n");
  1892. #endif
  1893.  
  1894.    demoenv = getenv("DEMOS");                   /* is a demo env var set? */
  1895.    if (demoenv != NULL)
  1896.       demoenvlen = strlen(demoenv);             /* find the string length */
  1897.    else
  1898.       {
  1899.       demoenv = (char *)malloc(5);              /* otherwise, malloc space */
  1900.       strcpy(demoenv, "/usr");                  /* and set it to /usr */
  1901.       demoenvlen = strlen(demoenv);             /* and set its length */
  1902.       }
  1903.    xenv = getenv("XDEMOS");                     /* is xdemo env var set? */
  1904.    if (xenv != NULL)
  1905.       xenvlen = strlen(xenv);                   /* find the length of it */
  1906.    else
  1907.       {
  1908.       xenv = (char *)malloc(15);                /* otherwise malloc space */
  1909.       strcpy(xenv, "/usr/demos/bin");           /* and set it to /usr/demos/bin
  1910. */
  1911.       xenvlen = strlen(xenv);                   /* and set the length */
  1912.       }
  1913.    sbenv = getenv("SBIN");                      /* is sbin env. var set? */
  1914.    if (sbenv != NULL)
  1915.       sbenvlen = strlen(sbenv);                 /* get its length */
  1916.    else
  1917.       {
  1918.       sbenv = (char *)malloc(15);               /* otherwise, malloc space */
  1919.       strcpy(sbenv, "/usr/demos/bin");          /* and set to /usr/demos/bin */
  1920.       sbenvlen = strlen(sbenv);                 /* and set its length */
  1921.       }
  1922. #ifdef DEBUG
  1923. printf(" done with env variables \n");
  1924. #endif
  1925.    for (i = 1; i < argc; i++)                    /* lets look at args */
  1926.       {
  1927.         char *arg = argv[i];
  1928.         if (arg[0] == '-') {            /* process command line switches */
  1929.             int len = strlen (arg);
  1930.             switch (arg[1]) {
  1931.               case 'h':
  1932.                 if (len >= 5 && strncmp(arg, "-hide", len) == 0)
  1933.                     Hide = TRUE;        /* hide demos that aren't present */
  1934.                 break;
  1935.               case 'v':
  1936.                     ViewOnly = TRUE;    /* kind of like 'demo' mode */
  1937.                 break;                  /* you can't change anything */
  1938.               case 'a':
  1939.                 if (len >= 6 && strncmp(arg, "-audio", len) == 0)
  1940.                     Audio = TRUE;       /* let's use sounds! */
  1941.                 break;
  1942.               default:
  1943.                 BadCommand = TRUE;      /* if nothing applies, it's bad */
  1944.                 break;
  1945.             }
  1946.         }               /* if it doesn't have a - in front, it's a file name */
  1947.         else {                        /* process command line parameters */
  1948.             FileName = (char *)malloc( sizeof(char) * (strlen(argv[i]) +1) );
  1949.             strcpy(FileName, argv[i]);
  1950.         }
  1951.    }
  1952.  
  1953.    DBtoplevel = XtAppInitialize(        /* topmost widget */
  1954.         &DBapp_context,
  1955.         "Demobook",
  1956.         NULL, 0,
  1957.         &argc, argv,
  1958.         NULL,
  1959.         NULL,
  1960.         0);
  1961.  
  1962.    create_widgets(DBtoplevel);          /* build the menus */
  1963.    init_motif_interface(argc,argv);     /* initialize motif interface */
  1964.    XtRealizeWidget(DBtoplevel);
  1965.  
  1966.    setbusycursor();                     /* draw init window */
  1967.  
  1968.    Create_motif_widgets();              /* create remaining motif widgets */
  1969.    installcmap(DBtoplevel, MainGL);     /* install color map */
  1970.  
  1971.    if (BadCommand)
  1972.       {
  1973.       sprintf(msgstring, "Could not interpret what you\ntyped on the command line:\nTry demobook [input filename] [-hide] [-audio] [-v]");
  1974.       DialogType = 1;
  1975.       popup_Message();
  1976.       }
  1977.  
  1978.    if (FileName != NULL) read_file(FileName);       /* read the input file */
  1979.  
  1980.    clearbusycursor();                   /* clear init window */
  1981.    exposeCB_Main(MainGL, 0, 0);         /* draw complete window */
  1982.  
  1983. /*   MB 5/4/93  temporarily taking the color picker out of demobook,
  1984. it seems to cause lots of bugs.
  1985.    if (!ViewOnly)
  1986. {
  1987.       setup_colors_widget();
  1988. }
  1989. */
  1990.  
  1991.    newgrpptr = NULL;
  1992.    curnewpage = NULL;
  1993.    curgroup = NULL;
  1994.  
  1995.    /* Play a musical intro */
  1996.    if (Audio) {
  1997.        if ( audio_lib_capable() ) {
  1998.            if (access("/usr/sbin/playaiff", F_OK) == 0) {
  1999.                if (access("/usr/lib/sounds/prosonus/musictags/tag3.aiff", F_OK) == 0)
  2000.                    system("playaiff /usr/lib/sounds/prosonus/musictags/tag3.aiff &");
  2001.                else {
  2002.                    sprintf(msgstring, "\nAudio file \n/usr/lib/sounds/prosonus/musictags/tag3.aiff\nnot found.\n");
  2003.                    popup_Message();
  2004.                    Audio = FALSE;
  2005.                }
  2006.                if (access("/usr/lib/sounds/prosonus/musictags/tag2.aiff", F_OK) != 0)
  2007.                    Audio = FALSE;
  2008.                }
  2009.            else {
  2010.                sprintf(msgstring, "Audio program \n/usr/sbin/playaiff\nnot found.");
  2011.                popup_Message();
  2012.                Audio = FALSE;
  2013.            }
  2014.        }
  2015.        else {
  2016.            sprintf(msgstring, "\nAudio capability is not \nsupported on this workstation.\n");
  2017.            popup_Message();
  2018.            Audio = FALSE;
  2019.        }
  2020.    }
  2021.    if (message_waiting) {
  2022.        popup_Message();
  2023.        message_waiting = FALSE;
  2024.    }
  2025.    XtAppMainLoop(DBapp_context);
  2026. }
  2027.